/**
 * (●'◡'●) Created by xxy on 2017/7/18 17:08
 */

function jsonp(obj) {
    if(!obj.url)return console.error("url is Wrong~");
    if(!obj.success||typeof obj.success!="function")return console.error("success is Wrong~");
    obj.jsonp = obj.jsonp || "callback";
    obj.jsonpCallback = obj.jsonpCallback || "myJsonp_"+new Date().getTime()+("_"+Math.random()).replace(".","");
    obj.data = obj.data || {};
    
    obj.data[obj.jsonp] = obj.jsonpCallback;
    var params = [];
    for(var i in obj.data){
        params.push(i+"="+obj.data[i]);
    }
    var sendData = params.join("&");

    window[obj.jsonpCallback] = function (data) {
        obj.success(data)
    };

    var oS = document.createElement("script");
    oS.src = obj.url + "?" + sendData;
    document.head.appendChild(oS);
} 
